package LCR;

public class isPalindrome2 {
    public boolean isPalindrome2(ListNode head) {
        ListNode s = head;
        int len = 0;
        while(s != null) {
            len++;
            s = s.next;
        }
        int[] ret = new int[len];
        int i = 0;
        while (head != null) {
            ret[i] = head.val;
            i++;
            head = head.next;
        }
        int left = 0;
        int right = len-1;
        while(left < right) {
            if(ret[left] != ret[right]){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
